//网络请求promise封装
const app = getApp();
const request = (params) => {
  return new Promise((resolve, reject) => {
    if(!params.noShowLoading){
      wx.showLoading({
        title: '加载中...'
      });
    }
    wx.request({
      url: app.globalData.requestUrl,
      data: params.data,
      headers: params.headers || {
        "content-Type": "application/x-www-form-urlencoded"
      },
      method: params.method || 'GET',
      dataType: params.dataType || 'json',
      success: function(res) {
        //执行resolve成功操作
        resolve(res.data)
        //执行reject失败操作
        //reject(res.data)
      },
      fail: function(e) {
        wx.hideLoading();
        wx.showToast({
          title: "网络请求错误"
        })
        reject(e)
      }
    })
  })
}
module.exports = {
  request: request
}